
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";

//入库操作请求API
export const halfhourcombinePropsApi = createApi({
    reducerPath: 'halfhourcombineprops',
    //设置基本请求路径
    baseQuery: fetchBaseQuery({
        baseUrl: window.app
    }),
    tagTypes: ['halfhourcombineprops'],//定义标签
    endpoints(build) {
        return {
            //获取入库记录
            gethalfhourcombineprops: build.query({
                query: (para) => ({
                    url: 'DW_PropsHalfHourCombine/GetPropsHalfHourCombine',
                    method: 'GET',
                    params: para,
                }),
                transformResponse(baseQuery) {
                    return baseQuery;

                },
                //设置缓存时间60秒
                keepUnusedDataFor:60,
                providesTags: ['halfhourcombineprops']//定义标签，如果该标签失效则会触发重新访问服务器
            }),
            //添加一条商品入库记录
            postaddhalfhourcombineprops: build.mutation({
                query(data) {
                    return {
                        url: 'DW_PropsHalfHourCombine/AddPropsHalfHourCombine',
                        method: 'POST',
                        body: data
                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery.data;

                },
                invalidatesTags: ['halfhourcombineprops']
            }),

            //修改一条商品入库记录
            putedithalfhourcombineprops: build.mutation({
                query(data) {
                    return {
                        url: 'DW_PropsHalfHourCombine/EditPropsHalfHourCombine',
                        method: 'PUT',
                        body: data
                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery.data;

                },
                invalidatesTags: ['halfhourcombineprops']//定义标签，一旦修改数据，则会使该标签失效
            }),
            posthalfhourcombineexcute: build.mutation({
                query: (data) => ({
                    url: 'DW_PropsHalfHourCombine/ExcuteDataHalfHourCombine',
                    method: 'POST',
                    body: data,
                }),
                transformResponse(baseQuery) {
                    return baseQuery.data;

                },

            }),
            //删除一条商品入库记录
            delethalfhourcombineprops: build.mutation({
                query(key) {
                    return {
                        url: `DW_PropsHalfHourCombine/DelPropsHalfHourCombine?key=${key}`,
                        method: 'DELETE',

                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery.data;

                },
                invalidatesTags: ['halfhourcombineprops']//定义标签，一旦修改数据，则会使该标签失效
            }),
        }
    }
});


//导出钩子函数给外部使用，自动生成hooks的名称为`use(Endpoint_name)Query`
export const { useGethalfhourcombinepropsQuery, usePostaddhalfhourcombinepropsMutation, usePutedithalfhourcombinepropsMutation, usePosthalfhourcombineexcuteMutation, useDelethalfhourcombinepropsMutation } = halfhourcombinePropsApi;